package maliklund87.spiritrpg;

import maliklund87.spiritrpg.dao.ImageLoader;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class BattleScene implements LogicHandler {
	private LogicManager logicManager;
	private Image backgroundImg;
	private Image dot;
	
	private Position[][] grid = new Position[24][13];
	
	public BattleScene(LogicManager logicManager){
		this.logicManager = logicManager;
	}

	@Override
	public void render(GameContainer gameContainer, Graphics graphics)
			throws SlickException {
		backgroundImg.draw(0, 0);
		
		for (int y = 0; y < grid[0].length; y++){
			for (int x = 0; x < grid.length; x++){
				Position p = grid[x][y];
				dot.draw(p.getX(), p.getY(), 0.5f);
			}
		}
	}

	@Override
	public void init(GameContainer gameContainer) throws SlickException {
		backgroundImg = ImageLoader.loadImage("data/battlescene_background.png");
		dot = ImageLoader.loadImage("data/dot.png");
		
		float startX = 40;
		float startY = 50;
		boolean even = false;
		float width = 50;
		for (int y = 0; y < grid[0].length; y++){
			for (int x = 0; x < grid.length; x++){
				grid[x][y] = new Position(startX + (width*x), startY+(width*y));
			}
			if (even){
				startX = startX - (width / 2);
				even = false;
			} else {
				startX = startX + (width / 2);
				even = true;
			}
			
		}
	}

	@Override
	public void update(GameContainer gameContainer, float delta)
			throws SlickException {
		Input input = gameContainer.getInput();
		if (input.isKeyPressed(Input.KEY_ESCAPE)){
			logicManager.setLogicHandler(new MainMenu(logicManager));
		}
	}

	@Override
	public void exit() {

	}

}
